package com.nit.lab.vote.mapper.basic;

import com.nit.lab.vote.dto.basic.SubjectDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SubjectMapper {
    @Select("<script>select *, subject_id As `key` from subject " +
            "where true " +
            "<if test = 'subjectName != null' >And subjectName like concat （'%', #{subjectName}, '%'）</if>" +
            "ORDER BY " +
            "<if test='sortField != null'> ${sortField} ${sortOrder}, </if>" +
            "gmt_create desc " +
            "</script>")
    List<SubjectDTO> list4Table(
            @Param("subjectName")String subjectName,
            @Param("start") Integer start,
            @Param("length") Integer length,
            @Param("sortField") String sortField,
            @Param("sortOrder") String sortOrder) throws Exception;

    @Select("<script>select count(*) from subject " +
            "where true " +
            "<if test = 'subjectName != null'>And subjectName like concat （'%', #{subjectName}, '%'）</if>" +
            "</script>")
    Long count4Table(
            @Param("subjectName") String subjectName) throws Exception;
}
